package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.ContractDao;
import com.x.erp.model.Contract;
import com.x.erp.rpc.ContractRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Service(interfaceName = "com.x.erp.rpc.ContractRpcService", timeout = 60000)
public class ContractService extends BaseService implements ContractRpcService {

	@Autowired
	private ContractDao contractDao;

	@Override
	public List<Contract> selectContractList(Contract contract) {
		try {
			return contractDao.selectContractList(contract);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public int selectContractNum(Contract contract) {
		try {
			return contractDao.selectContractNum(contract);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public Contract insertContract(Contract contract) {
		try {
			return this.insert(contract);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public void updateContract(Contract contract) {
		try {
			contract.setContractUpdateTime(this.getDate(0));
			this.update(contract);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public int updateContractExpireState(Contract contract) {
		try {
			return contractDao.updateContractExpireState(contract);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

}
